<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
	String basePath = "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="/">
    <!-- 下拉框 -->
    <link rel="stylesheet" href="static/ace/css/chosen.css"/>
    <link href="plugins/kindeditor/themes/simple/simple.css" type="text/css" rel="stylesheet">
    <link rel="stylesheet" href="static/ace/css/datepicker.css"/>
    <link href="//cdn.bootcss.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet">
    <!-- jsp文件头和头部 -->
    <%@ include file="../index/top.jsp" %>
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <form action="setMeal/${msg }.do" name="plantbaseForm" id="plantbaseForm" method="post">
                            <c:if test="${meal.id !=null}">
                                <input type="hidden" name="id" id="id" value="${meal.id }"/>
                            </c:if>
                            <div id="zhongxin" style="padding-top: 13px;">
                                <table id="table_report" class="table table-striped table-bordered table-hover">
                                	<tr>
                                        <td style="width:200px;text-align: right;padding-top: 20px;">套餐期号:</td>
                                        <td><input type="number"  value="${meal.time_id }" min="1"
                                                   maxlength="11" name="time_id" id="time_id" 
                                                   style="width:98%;"/></td>
                                    </tr>
									<tr>
                                        <td style="width:200px;text-align: right;padding-top: 20px;">套餐名称:</td>
                                        <td><input type="text"  value="${meal.name }" 
                                                   maxlength="32" name="name" id="name" 
                                                   style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">套餐功效:</td>
                                        <td><input type="text"  value="${meal.package_efficacy }"
                                                   maxlength="10" name="package_efficacy" id="package_efficacy"
                                                   style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">套餐价格:</td>
                                        <td><input type="number"  value="${meal.price }" min="0"
                                                   maxlength="10" name="price" id="price"
                                                   style="width:98%;"/></td>
                                    </tr>
                                       <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">库存数量:</td>
                                        <td><input type="number" value="${meal.stock_num }" min="0"
                                                   maxlength="10" name="stock_num" id="stock_num"
                                                   style="width:98%;"/></td>
                                    </tr>
                                    <tr>
											<td
												style="width: 100px; text-align: right; padding-top: 13px;">已售数量:</td>
											<td><input type="number" name="sale_num" id="sale_num"
												value="${meal.sale_num }" maxlength="11" min="0" 
												style="width: 98%;" /></td>
										</tr>
										<tr>
											<td
												style="width: 100px; text-align: right; padding-top: 13px;">最低售买数量:</td>
											<td><input type="number" name="min_shop_num"
												id="min_shop_num" value="${meal.min_shop_num }"
												maxlength="10" min="0" style="width: 98%;" /></td>
										</tr>
										<tr>
											<td
												style="width: 100px; text-align: right; padding-top: 13px;">最高售买数量:</td>
											<td><input type="number" name="max_shop_num"
												id="max_shop_num" value="${meal.max_shop_num }"
												maxlength="10" min="0" style="width: 98%;" /></td>
										</tr>
										<tr>
											<td
												style="width: 110px; text-align: right; padding-top: 13px;">套餐权益周期
												(月):</td>
											<td><input type="number" name="equity_cycle"
												id="equity_cycle" value="${meal.equity_cycle }"
												maxlength="11" min="1" style="width: 98%;" /></td>
										</tr>
										  <tr>
					                        <td
					                          style="width: 30px; text-align: right; padding-top: 13px;">销售时间:</td>
					                        <td colspan="3"><span class="dib vm">上架时间:&nbsp;</span><input
					                          id="start_time" name="start_time"
					                          placeholder="请选择上架时间"
					                          value="${meal.start_time }" />&emsp; <span
					                          class="dib vm">下架时间 :&nbsp;</span><input
					                          class="dib vm" id="end_time" name="end_time"
					                          placeholder="请选择下架时间 " value="${meal.end_time }" />
					                          &emsp; <span
					                          class="dib vm">售罄时间 :&nbsp;</span><input
					                          class="dib vm" id="sale_time" name="sale_time"
					                          placeholder="请选择售罄时间" value="${meal.sale_time }" />
					                          &emsp; <span
					                          class="dib vm">截止使用时间 :&nbsp;</span><input
					                          class="dib vm" id="end_use_time" name="end_use_time"
					                          placeholder="请选择截止使用时间" value="${meal.end_use_time }" /></td>
					                      </tr>
									<%-- 	<tr>
											<td
												style="width: 100px; text-align: right; padding-top: 13px;">截止使用时间:
											</td>
											<td><span class="dib vm">截止使用时间:&nbsp;</span><input
												id="end_use_time" name="end_use_time"
												placeholder="请选择截止使用时间" value="${meal.end_use_time }" /></td>
										</tr> --%>
                                        <tr>
                                        <td
                                            style="width: 85px; text-align: right; padding-top: 15px;">封面图:
                                        </td>
                                        <td><a href="javascript:void(0)" class="onePicUpload">上传图片</a> 
                                        <c:if test="${not empty meal.top_picture}">
                                            <a href='${meal.top_picture }' target='_blank'><img src='${meal.top_picture }'
                                             width='80' height='50'/></a>
                                        </c:if> <input type="hidden" name="top_picture" id="top_picture"
                                                       value="${meal.top_picture }"/></td>
                                    </tr>
                                      <tr>
                                        <td
                                            style="width: 85px; text-align: right; padding-top: 15px;">缩略图:
                                        </td>
                                        <td><a href="javascript:void(0)" class="onePicUpload">上传图片</a> 
                                        <c:if test="${not empty meal.thumbnail}">
                                            <a href='${meal.thumbnail }' target='_blank'><img src='${meal.thumbnail }'
                                             width='80' height='50'/></a>
                                        </c:if> <input type="hidden" name="thumbnail" id="thumbnail" value="${meal.thumbnail }"/></td>
                                    </tr>
                                     <tr>
                                        <td
                                                style="width: 79px; text-align: right; padding-top: 13px;">展示图片:
                                        </td>
                                        <td><a href="javascript:void(0)"
                                               class="picFileUpload">上传图片</a> <input
                                                type="hidden" id="picture" name="picture"
                                                value="${meal.picture }"/></td>
                                    </tr>
                                      <tr>
                                        <td
                                           style="width: 79px; text-align: right; padding-top: 13px;">图文详情:
                                        </td>
                                        <td>
                          				<textarea class="content" style="width: 1000px; height: 400px;"
                                   	    name="content" id="content">${meal.content}</textarea>
                                        </td>
                                    </tr>
                                   
                                </table>
                                <table id="table_report1" class="table table-striped table-bordered table-hover">
                                    <tr>
                                        <td style="text-align: center;" colspan="10">
                                                <a class="btn btn-mini btn-primary" onclick="save();">保存</a>
                                            <a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div id="zhongxin2" class="center" style="display:none"><br/><br/><br/><br/><img
                                    src="static/images/jiazai.gif"/><br/><h4 class="lighter block green"></h4></div>
                        </form>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
</div>
<!-- /.main-container -->
<!-- basic scripts -->
<!-- 页面底部js¨ -->
<%@ include file="../index/foot.jsp" %>
<!-- ace scripts -->
<script src="static/ace/js/ace/ace.js"></script>
<!-- inline scripts related to this page -->
<!-- 下拉框 -->
<script src="static/ace/js/chosen.jquery.js"></script>
<!--提示框-->
<script type="text/javascript" src="static/js/jquery.tips.js"></script>
<script type="text/javascript" src="static/js/common/file_upload.js"></script>
<script type="text/javascript" src="plugins/kindeditor/kindeditor-all.js"></script>
<script type="text/javascript" src="plugins/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript" src="static/laydate/laydate.js"></script>
<script type="text/javascript" src="static/js/provincial.municipal.league.js"></script>
</body>
<script type="text/javascript">
    $(top.hangge());
   
    $(function () {

       /*  SpecificationsBtn(); */
        //创建富文本编辑器
        TAOTAO.kingEditorParams = {
            //指定上传文件参数名称
            filePostName: "uploadFile",
            //指定上传文件请求的url。
            uploadJson: '<%=basePath%>pic/upload',
            //上传类型，分别为image、flash、media、file
            dir: "image",
            extraFileUploadParams: {isCom: "01", width: 800, height: 800, quality: 0.8, end: "view"}
        }

        TAOTAO.kingEditorAutoParams = {
            //指定上传文件参数名称
            filePostName: "uploadFile",
            //指定上传文件请求的url。
            uploadJson: '<%=basePath%>pic/upload',
            //上传类型，分别为image、flash、media、file
            dir: "image",
            extraFileUploadParams: {isCom: "01", width: 200, height: 200, quality: 1, end: "thumb"}
        }

        goodsAddEditor = TAOTAO.createEditor("#plantbaseForm [name=content]");
        //初始化类目选择和图片上传器
        TAOTAO.initPicUpload($("input[name=picture]").val());
        TAOTAO.initOnePicUpload($("input[name=top_picture]").val());


        $('body').on('click', '.imageButton', function () {
            var id = $("#id").val();
            var picture = $("#picture").val();
            var imgsrc = $(this).parent('li').find("img").attr("src");
            var _this = $(this);
            var others = $(this).parent('li').siblings()

            var newPicture = "";
            if (picture.indexOf((imgsrc + ',')) > -1) {
                newPicture = picture.replace((imgsrc + ','), '');
            } else if (picture.indexOf((',' + imgsrc)) > -1) {
                newPicture = picture.replace((',' + imgsrc), '');
            }
            $.ajax({
                url: "<%=basePath%>pic/mealPicDelete",
                type: "post",
                async: true,
                dataType: "text",
                data: {"id": id, "newPicture": newPicture, "imgsrc": imgsrc, "state": "00"},
                success: function (data) {
                    if (data == "success") {
                        _this.parent('li').remove();
                        var html = ''
                        for (var i = 0; i < others.length; i++) {
                            var $item = $(others[i])
                            var val = $item.find('img').attr('src')
                            html += val + ','
                        }
                        console.log(html)

                        $("#picture").val(html);
                    }
                }, error: function (XMLHttpRequest, textStatus) {
                    alealert(textStatus);
                }
            });
        });
    });
    
    function save(){
    	 if($.trim($("#time_id").val()) == ""){
    		 alert("请填写套餐期号");
		    	return false;
    	 }
    	 if ($.trim($("#time_id").val()) <= 0) {
 			alert("套餐期号不能小于1!")
 			return false;
 		 }
    	 if($.trim($("#name").val()) == ""){
    		 alert("请填写套餐名称");
		    	return false;
    	 }
    	 if($.trim($("#package_efficacy").val()) == ""){
    		 alert("请填写套餐功效");
		    	return false;
    	 }
    	 if($.trim($("#price").val()) == ""){
    		 alert("请填写套餐价格");
		    	return false;
    	 }
    	 if($.trim($("#price").val()) <=0){
    		 alert("请正确填写套餐价格");
		    	return false;
    	 }
    	 if($.trim($("#stock_num").val()) == ""){
    		 alert("请填写套餐库存");
		    	return false;
    	 }
    	 if($.trim($("#stock_num").val()) < 0){
    		 alert("请正确填写套餐库存");
		    	return false;
    	 }
    	 if($.trim($("#sale_num").val()) == ""){
    		 alert("请填写套餐已售数量");
		    	return false;
    	 }
    	 if ($.trim($("#min_shop_num").val()) == "") {
 			alert("请输入最低起售数量!")
 			return false;
 		}
 		if ($.trim($("#max_shop_num").val()) == "") {
 			alert("请输入最高起售数量!")
 			return false;
 		}
 		if (($.trim($("#max_shop_num").val()) - $.trim($("#min_shop_num").val())) <= 0) {
 			alert("最高起售数量要大于最低起售数量")
 			return false;
 		}
 		if ($.trim($("#equity_cycle").val()) == "") {
 			alert("请输入套餐权益周期!")
 			return false;
 		}
 		if ($.trim($("#equity_cycle").val()) <= 0) {
 			alert("权益周期不能小于1!")
 			return false;
 		}
 		if($.trim($("#start_time").val())==""){
	        alert("请选择套餐上架时间！");
	        return false;
        }
	    if($.trim($("#end_time").val())==""){
	        alert("请选择套餐下架时间！");
	        return false;
        }
	    if($.trim($("#sale_time").val())==""){
	        alert("请选择套餐售罄时间！");
	        return false;
        }
 		if ($.trim($("#end_use_time").val()) == "") {
			alert("请选择套餐截止使用时间!")
			return false;
		}
   	    if ($.trim($("#top_picture").val()) == "") {
            alert("请上传套餐封面图");
            return false;
        }
   	    if ($.trim($("#picture").val()) == "") {
            alert("请上传套餐展示图");
            return false;
        }
   	    if (goodsAddEditor.isEmpty()) {
            alert("请上传图文详情");
            return false;
        }
	   	goodsAddEditor.sync();
	   	$("#plantbaseForm").submit();
        $("#zhongxin").hide();
        $("#zhongxin2").show();
    		
    }
    
    laydate({
		elem : '#end_use_time',
		format : 'YYYY-MM-DD hh:mm:ss',
		min : laydate.now(),
		max : '2099-06-16 23:59:59',
		istime : true,
		istoday : true,
		choose : function(datas) {
		}
	});
    
    var startTime = {
      	    elem : '#start_time',
      	    format : 'YYYY-MM-DD hh:mm:ss',
      	    min : laydate.now(), //设定最小日期为当前日期
      	    max : '2099-06-16 23:59:59', //最大日期
      	    istime : true,
      	    istoday : true,
      	    choose : function(datas) {
      	      endTime.min = datas; //开始日选好后，重置结束日的最小日期
      	      endTime.start = datas //将结束日的初始值设定为开始日
      	    }
      	  };

      	  var endTime = {
      	    elem : '#end_time',
      	    format : 'YYYY-MM-DD hh:mm:ss',
      	    min : laydate.now(),
      	    max : '2099-06-16 23:59:59',
      	    istime : true,
      	    istoday : true,
      	    choose : function(datas) {
      	      startTime.max = datas; //结束日选好后，重置开始日的最大日期
      	    }
      	  };
      	  
      	var sale_time = {
      	  	    elem : '#sale_time',
      	  	    format : 'YYYY-MM-DD hh:mm:ss',
      	  	    min : laydate.now(),
      	  	    max : '2099-06-16 23:59:59',
      	  	    istime : true,
      	  	    istoday : true,
      	  	    choose : function(datas) {
      	  	      startTime.max = datas; //结束日选好后，重置开始日的最大日期
      	  	    }
      	  	  };
      	 laydate(startTime);
      	  laydate(endTime);
      	laydate(sale_time);
    

</script>
</html>